﻿using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using yunbo.Model.RMM;
using yunbo.Repositorys.RMMRepositorys;

namespace yunbo.Controllers.RMMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class Rm_yclcgController : Controller
    {
        Rm_yclcgRepository rm_YclcgRepository = new Rm_yclcgRepository();
        [HttpGet("GetFYRm_yclcg")]
        public IActionResult GetFYRm_yclcg(int PageNumber, int PageSize)
        {
            FYRm_yclcg  fYRm_Yclcg = rm_YclcgRepository.GetFYRm_yclcg(PageNumber,PageSize);
            
            return Ok(fYRm_Yclcg);
        }
        [HttpPost("Addyclcg")]
        public IActionResult Addyclcg(TJRm_yclcg rm_Yclcg)
        {
            Rm_yclcg rmcg = new Rm_yclcg()
            {
                yclcg_code=rm_Yclcg.yclcg_code,
                yclcg_ruck=rm_Yclcg.yclcg_ruck,
                yclcg_gys=rm_Yclcg.yclcg_gys,
                yclcg_ry=rm_Yclcg.yclcg_ry,
                yclcg_time=rm_Yclcg.yclcg_time,
                wl_code=rm_Yclcg.wl_code,
                yclcg_zkje=rm_Yclcg.yclcg_zkje,
                yclcg_fjje=rm_Yclcg.yclcg_fjje,
                yclcg_jsfs=rm_Yclcg.yclcg_jsfs,
                djbz=rm_Yclcg.djbz,
                create_by=rm_Yclcg.create_by,
                create_time=DateTime.Now,
                yclcg_zje=rm_Yclcg.yclcg_zje,
                yclcg_ssje=rm_Yclcg.yclcg_ssje,
                yclcg_djzt=rm_Yclcg.yclcg_djzt,
                yclcg_sl=rm_Yclcg.yclcg_sl,
                yclcg_zkl=rm_Yclcg.yclcg_zkl,
            };
            bool cg=rm_YclcgRepository.Addyclcg(rmcg) >0;
            return Ok(cg);
        }
        [HttpGet("Getcg")]
        public IActionResult Getcg(string code)
        {
            Rm_yclcg rm_Yclcg=rm_YclcgRepository.Get_Yclcg(code);
            return Ok(rm_Yclcg);
        }
        [HttpPut("UpdateYclcg_zt")]
        public IActionResult UpdateYclcg_zt(string up) 
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string de = $"dh{currentTime}{randomNumberString}";
            Rm_yclcg rm_Yclcg1=new Rm_yclcg() 
            {
                yclcg_code=up,
                dhzt=1,
                yclcg_djzt=2,
                dhcode=de,
            };

            bool rm_Yclcg = rm_YclcgRepository.UpdateYclcg(rm_Yclcg1) >0;
            return Ok(rm_Yclcg);
        }
        [HttpGet("Getdh")]
        public IActionResult Getdh(int PageNumber, int PageSize)
        {
            FYRm_yclcg fYRm_Yclcg = rm_YclcgRepository.Getdh(PageNumber, PageSize);
            return Ok(fYRm_Yclcg);
        }

        [HttpPut("UpZt")]
        public IActionResult UpZt(string code)
        {
            bool zt=rm_YclcgRepository.Updhzt(code)>0;
            return Ok(zt);
        }
        [HttpPut("UpZtbtg")]
        public IActionResult UpZtbtg(string code)
        {
            bool zt = rm_YclcgRepository.Updhztbtg(code) > 0;
            return Ok(zt);
        }

        [HttpPut("UpRk")]
        public IActionResult UpRk(Uprkzt uprkzt)
        {
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string code = $"rk{currentTime}{randomNumberString}";
            Rm_yclcg rm_Yclcg=new Rm_yclcg()
            {
                yclcg_code = uprkzt.yclcg_code,
                rkzt = 1,
                rklx ="原材料入库",
                rkcode = code,
                jhrktime = DateTime.Now.AddDays(2),
            };
            bool rk = rm_YclcgRepository.Uprk(rm_Yclcg) > 0;
            return Ok(rk);
        }
        [HttpGet("Getrk")]
        public IActionResult Getrk(int PageNumber, int PageSize)
        {
            FYRm_yclcg fYRm_Yclcg = rm_YclcgRepository.Getrk(PageNumber, PageSize);

            return Ok(fYRm_Yclcg);
        }
        [HttpPut("Uprkzt")]
        public IActionResult Uprkzt(string code )
        {
            bool rkzt=rm_YclcgRepository.Uprkzt(code)>0;
            return Ok(rkzt);
        }
        [HttpPut("Upcgsh")]
        public IActionResult Upchsh(UpRm_yclcg upRm_Yclcg)
        {
            upRm_Yclcg.yclcg_djzt = 1;
            bool sh=rm_YclcgRepository.Updatesh(upRm_Yclcg)>0;
            return Ok(sh);
        }
    }
}
